home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung / Power-Programmierung (Tewi)(1994).iso / acad / autolisp / sv_env / sv-env.lsp
Lisp/Scheme  |  1989-09-24  |  6KB  |  111 lines

  1. ;;; -*-  Mode: LISP -*- Syntax: AutoLISP (C) Benjamin Olasov 1988
  2. ;;;      environment writing function **Release 9**
  3.  
  4. ;;; -*-  Mode: LISP -*- Syntax: AutoLISP (C) Benjamin Olasov 1988, 1989
  5.  
  6. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  7. ;;; File: SV-ENV.LSP Copyright (C) Benjamin Olasov    Graphic Systems, Inc. ;;;
  8. ;;; Inquiries:                                                              ;;;
  9. ;;;                                                                         ;;;
  10. ;;;     Benjamin Olasov                                                     ;;;
  11. ;;;     Graphic Systems, Inc.:                                              ;;;
  12. ;;;                                                                         ;;;
  13. ;;;                    New York, NY:   PH (212) 725-4617                    ;;;
  14. ;;;                    Cambridge, MA:  PH (617) 492-1148                    ;;;
  15. ;;;                    MCI-Mail:       GSI-NY   344-4003                    ;;;
  16. ;;;                    Arpanet:        olasov@cs.columbia.edu               ;;;
  17. ;;;                                                                         ;;;
  18. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  19.  
  20. ;; This program is provided 'as is' without warranty of any kind, either 
  21. ;; expressed or implied, including, but not limited to the implied warranties of
  22. ;; merchantability and fitness for a particular purpose.  The entire risk as to
  23. ;; the quality and performance of the program is with the user.  Should the 
  24. ;; program prove defective, the user assumes the entire cost of all necessary 
  25. ;; servicing, repair or correction. 
  26. ;;
  27. ;; AutoLisp and AutoCad are registered trademarks of AutoDesk, Inc.
  28.  
  29. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  30. ;; This function C:SV-ENV saves the current LISP environment into a file with
  31. ;; the name of the drawing and with the extension .LSP.  For example, if the
  32. ;; name of the current drawing whose LISP environment you wish to save is
  33. ;; FOOBAR.DWG, then the name of the LISP file to which the environment is saved
  34. ;; will be FOOBAR.LSP.
  35. ;; For this function to work at all, you must have placed a marker in your
  36. ;; ATOMLIST (AutoLISP's record of all LISP variables, functions, etc.).
  37. ;; To do this, simply place the following line at the end of your ACAD.LSP file:
  38. ;; (setq MARK nil)
  39. ;; That's all.  Then the SV-ENV function will not attempt to record 
  40. ;; AutoLISP's primitive functions, or the functions automatically loaded with
  41. ;; your ACAD.LSP.
  42. ;;
  43. ;; To restore your previous environment of variables and user functions, just
  44. ;; type (load "dwgname") at the command prompt, where "dwgname" is the name
  45. ;; of the drawing whose LISP environment you saved.
  46.  
  47. ;; This is a beta version, which I hope to improve soon.
  48. ;; If you have ideas on how to improve this, please don't just munge this file
  49. ;; and redistribute it- let me hear your ideas.  If they would create errors
  50. ;; of which I'm aware, I'll let you know- if not, I'll include them in a 
  51. ;; revision. 
  52.  
  53. (defun C:SV-ENV (/ usr-atoms dwgname file-spec)
  54.       (if (setq usr-atoms (cdr (member 'MARK (reverse ATOMLIST))))
  55.           (progn
  56.               (princ usr-atoms) (terpri)
  57.               (setq dwgname (getvar "dwgname") counter 0)
  58.               (setq file-spec (open (strcat dwgname ".lsp") "w"))
  59.               (foreach atm usr-atoms
  60.                        (write-atom atm file-spec))
  61.               (close file-spec)
  62.               (princ "\nWrote ")
  63.               (princ counter)
  64.               (princ " expressions to ")
  65.               (princ (strcase dwgname))
  66.               (princ ".LSP.")
  67.               (princ))
  68.          (if (null ATOMLIST)
  69.              (prompt "\nCan't evaluate ATOMLIST.")
  70.              (prompt "\nNo marker present in atomlist."))))
  71.  
  72. (defun write-atom (atm filespec)                   ;; beta version
  73.        (cond  ((or (= (type (eval atm)) 'LIST)
  74.                    (= (type (eval atm)) 'ENAME))
  75.                (princ (strcat (chr 40) "setq ") filespec)
  76.                (prin1 atm filespec)
  77.                (princ (strcat " " (chr 39)) filespec)
  78.                (prin1 (eval atm) filespec)
  79.                (princ (strcat (chr 41) "\n") filespec)
  80.                (setq counter (1+ counter)))
  81.               ((or (= (type (eval atm)) 'SYM)
  82.                    (= (type (eval atm)) 'INT)
  83.                    (= (type (eval atm)) 'REAL)
  84.                    (= (type (eval atm)) 'STR)
  85.                    (= (type (eval atm)) 'PAGETB))
  86.                (princ (strcat (chr 40) "setq ") filespec)
  87.                (prin1 atm filespec)
  88.                (princ " " filespec)
  89.                (prin1 (eval atm) filespec)
  90.                (princ (strcat (chr 41) "\n") filespec)
  91.                (setq counter (1+ counter)))
  92.               ((null (eval atm))
  93.                (princ "\nIgnoring null expression ") (princ atm))
  94.               (T (princ "\nI don't know how to handle ")
  95.                  (princ atm))))
  96.  
  97. (setq MARK 'T)    ;; this places a marker in ATOMLIST for 
  98.                    ;; later saving LISP environment
  99.  
  100. (setvar "cmdecho" 0)
  101. (command "textscr")
  102. (repeat 24 (terpri))
  103. (princ "\nFor this function to work at all, you must have placed a marker in your")
  104. (princ "\nATOMLIST (AutoLISP's record of all LISP variables, functions, etc.).")
  105. (princ "\nTo do this, simply place the following line at the end of your ACAD.LSP file:")
  106. (princ "\n\(setq MARK 'T\)")
  107. (princ "\nTo use SV-ENV, type SV-ENV at the command prompt.")
  108. (princ)
  109.  
  110.  
  111.